﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CafeOnline.Controllers.Filters;
using CafeOnline.Domain.Entities;
using CafeOnline.Domain.Models;
using CafeOnline.Models;
using CafeOnline.MvcFramework;
using CafeOnline.Domain.Repository;
using CafeOnline.Common;
using CafeOnline.MvcFramework.Composition;

namespace CafeOnline.Controllers {
    [CafeOnlineAuthorized]
    public class BaseTestController<T> : Controller where T : BaseEntity, new () {
        
        public IUserModel UserModel {
            get {
                return SessionFactory.GetSessionObject<IUserModel>();
            }
        }
        //
        // GET: /Base/


        protected virtual String Operation {
            get {
                return string.Empty;
            }
        }

        public virtual ActionResult Index() {
            InitSecurity();
            return View();
        }

        public virtual ActionResult Create() {
            InitSecurity();
            T model = new T();
            return PartialView();
        }

        public virtual ActionResult Edit() {
            InitSecurity();
            return View();
        }

        public virtual JsonResult Save(T model) {
            return Json("success", JsonRequestBehavior.AllowGet);
        }
        protected virtual bool InternalSave<TModel>(TModel model) where TModel : BaseModel {
            return true;
        }
        protected virtual void InitSecurity() {
            ViewBag.CanCreate = true;
            ViewBag.CanEdit = true;
            ViewBag.CanDelete = true;
            ViewBag.CanSave = true;
        }
    }
}